package com.yayyay.jwt.service.impl;

import cn.dev33.satoken.secure.SaSecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yayyay.commom.entity.SysUser;
import com.yayyay.commom.mapper.SysUserMapper;
import com.yayyay.jwt.model.dto.UserDTO;
import com.yayyay.jwt.service.UserService;
import org.springframework.stereotype.Service;

/**
 * @Author: liangSY
 * @Date: 2021/9/18 16:51
 * @ClassName: UserServicesImpl
 */
@Service
public class UserServicesImpl extends ServiceImpl<SysUserMapper,SysUser> implements UserService {


    @Override
    public SysUser findByAccount(String account) {
        LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(SysUser::getAccount,account);
        return getOne(queryWrapper);
    }

    @Override
    public boolean addSysUser(UserDTO dto) {
        SysUser user = new SysUser();
        user.setAccount(dto.getAccount());
        user.setPassword(SaSecureUtil.md5BySalt(dto.getPassword(),dto.getAccount()));
        return save(user);
    }
}
